package com.py.inbound.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.py.inbound.domain.OdRejectedDetails;
import com.py.inbound.domain.OdSaleRejected;
import com.py.inbound.domain.OdSaleRejectedDetails;
import com.py.inbound.service.IOdSaleRejectedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 销售退货Controller
 *
 * @author 童佳
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/rejected")
public class OdSaleRejectedController extends BaseController {
    @Autowired
    private IOdSaleRejectedService odSaleRejectedService;

    /**
     * 查询销售退货列表
     */
//    @RequiresPermissions("rejected:rejected:list")
    @GetMapping("/list")
    public TableDataInfo list(OdSaleRejected odSaleRejected) {
        startPage();
        List<OdSaleRejected> list = odSaleRejectedService.selectOdSaleRejectedList(odSaleRejected);
        return getDataTable(list);
    }

    /**
     * 导出销售退货列表
     */
    @RequiresPermissions("rejected:rejected:export")
    @Log(title = "销售退货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OdSaleRejected odSaleRejected) {
        List<OdSaleRejected> list = odSaleRejectedService.selectOdSaleRejectedList(odSaleRejected);
        ExcelUtil<OdSaleRejected> util = new ExcelUtil<OdSaleRejected>(OdSaleRejected.class);
        util.exportExcel(response, list, "销售退货数据");
    }

    /**
     * 获取销售退货详细信息
     */
    @RequiresPermissions("rejected:rejected:query")
    @GetMapping(value = "/{srId}")
    public AjaxResult getInfo(@PathVariable("srId") Integer srId) {
        return success(odSaleRejectedService.selectOdSaleRejectedBySrId(srId));
    }

    /**
     * 新增销售退货
     */
    @RequiresPermissions("rejected:rejected:add")
    @Log(title = "销售退货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OdSaleRejected odSaleRejected) {
        return toAjax(odSaleRejectedService.insertOdSaleRejected(odSaleRejected));
    }

    /**
     * 修改销售退货
     */
    @RequiresPermissions("rejected:rejected:edit")
    @Log(title = "销售退货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OdSaleRejected odSaleRejected) {
        return toAjax(odSaleRejectedService.updateOdSaleRejected(odSaleRejected));
    }

    /**
     * 删除销售退货
     */
    @RequiresPermissions("rejected:rejected:remove")
    @Log(title = "销售退货", businessType = BusinessType.DELETE)
    @DeleteMapping("/{srIds}")
    public AjaxResult remove(@PathVariable Integer[] srIds) {
        return toAjax(odSaleRejectedService.deleteOdSaleRejectedBySrIds(srIds));
    }

    @GetMapping("/selectOdSaleRejectedDetailsList")
    public TableDataInfo selectOdSaleRejectedDetailsList(OdSaleRejectedDetails odSaleRejectedDetails) {

        startPage();
        List<OdSaleRejectedDetails> odSaleRejectedDetailsList = odSaleRejectedService.selectOdSaleRejectedDetailsList(odSaleRejectedDetails);

        return getDataTable(odSaleRejectedDetailsList);

    }
}
